/*
* Ext JS Library 2.1
* Copyright(c) 2006-2008, Ext JS, LLC.
* licensing@extjs.com
* 
* http://extjs.com/license
*/

AdvancedSearchWindow = function() {


    this.form = new Ext.FormPanel({
        id: 'searchForm',
        labelAlign: 'top',
        width: 'auto',
        border: false,
        labelWidth: 75, // label settings here cascade unless overridden
        url: 'save-form.php',
        frame: true,
        bodyStyle: 'padding:5px 5px 0',
        width: 300,
        defaults: {  },
        items: [
    {   // MISC FIELDSET
        xtype: 'fieldset',
        hideLabels:false,
        autoHeight: true,
        title: 'Search Options',
        collapsible: false,
        //TODO: THESE CHECKBOXES NEED TO BE ADDED DYNAMICALLY BASED UPON PERMS
        items: [{
            xtype: 'textfield',
            fieldLabel: 'With all the words',
            name: 'allthewords',
            allowBlank: true,
            width: 260
        }, {
            xtype: 'textfield',
            fieldLabel: 'Exact Phrase',
            name: 'exactphrase',
            width: 260
        }, {
             xtype: 'textfield',
            fieldLabel: 'With at least one of the words',
            name: 'atleastwords',
            width: 260
        }, {
        xtype: 'textfield',
            fieldLabel: 'Without the words',
            name: 'excludewords'
        } 
        
]
    },
    
    { //DATE PANEL
        xtype: 'fieldset',
        hideLabels:false,
        autoHeight: true,
        title: 'Date Options',
        collapsible: true,
    items: [
     { name:'date1'
             ,fieldLabel:'Start Date'
             , xtype: 'datefield'
             , width: 130
    },
    { name: 'date2'
             , fieldLabel: 'End Date'
             , xtype: 'datefield'
               , width: 130
    }
    ]},
    
    
    
    { //SOURCES PANEL
        xtype: 'fieldset',
        tabTip: 'Choose the sources that AOSS will query by default. These can be changed on the fly in the advanced search dialog.',
        hideLabels:true,
        autoHeight: true,
        title: 'News Sources',
        collapsible: true,
        collapsed: true,
        //TOD: THESE CHECKBOXES NEED TO BE ADDED DYNAMICALLY BASED UPON PERMS
        items: [{
        
            name: 'JANES'
 ,boxLabel: 'Janes'
 , xtype: 'checkbox'
 
        },
        {
            name: 'AFP'
 , boxLabel: 'AFP'
 , xtype: 'checkbox'
        },
        {
            name: 'Reuters'
 , boxLabel: 'Reuters'
 , xtype: 'checkbox'
        },
        {
            name: 'AP'
 , boxLabel: 'AP'
 , xtype: 'checkbox'
        }
]
    } //END SOURCES PANEL
        ],
        buttons: [{
            text: 'Search AOSS',
            handler: this.onSearchClick,
            scope: this
        },
        {
            text: 'Save Query',
            handler: this.onSearchClick,
            scope: this
        }, {
            text: 'Cancel',
           handler: this.hide.createDelegate(this, [])
           // handler: this.hide()
}]

        });


        AdvancedSearchWindow.superclass.constructor.call(this, {
            stateful: false,
            title: 'Advanced Search',
            iconCls: 'feed-icon',
            id: 'advanced-search-win',
            autoHeight: true,
            width: 316,
            resizable: false,
            plain: true,
            modal: true,
            y: 100,
            autoScroll: true,
            closeAction: 'hide',

                items: this.form
            });

            this.addEvents({ add: true });
        }

        Ext.extend(AdvancedSearchWindow, Ext.Window, {

            onSearchClick: function() {
                // this.el.mask('Searching...', 'x-mask-loading');
                var values = this.form.getForm().getValues();
                this.hide(); //doesnt work properly FIXME

                return this.fireEvent('donesearch', {
                    url: values['allthewords'],
                    text: values['allthewords'],
                    description: 'boogywoogy' //find out what it does with this
                });

            },
            show: function() {
                if (this.rendered) {
                    //   this.feedUrl.setValue('');
                }
                AdvancedSearchWindow.superclass.show.apply(this, arguments);
            },



            markInvalid: function() {
                this.feedUrl.markInvalid('The URL specified is not a valid RSS2 feed.');
                this.el.unmask();
            },

            validateFeed: function(response, options) {




            }
        });